#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <netinet/in.h>

#define BUFF_SIZE 1024

int main()
{
    int sock_serv = socket(AF_INET, SOCK_STREAM, 0);

    struct sockaddr_in serv_addr;
    memset(&serv_addr, 0, sizeof(serv_addr));
    serv_addr.sin_family = AF_INET;
    serv_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
    serv_addr.sin_port = htons(1234);
    bind(sock_serv, (struct sockaddr*)&serv_addr, sizeof(serv_addr));

    listen(sock_serv, 20);

    struct sockaddr_in clnt_addr;
    socklen_t sock_clnt_size = sizeof(clnt_addr);
    char buffer[BUFF_SIZE] = {0};
    while (1)
    {
        int sock_clnt = accept(sock_serv, (struct sockaddr*)&clnt_addr, &sock_clnt_size);
        int strLen = recv(sock_clnt, buffer, BUFF_SIZE, 0);
        send(sock_clnt, buffer, strLen, 0);
        close(sock_clnt);
        memset(buffer, 0, BUFF_SIZE);
    }

    close(sock_serv);

    return 0;
}